package com.ruoyi.front.controller;

import com.ruoyi.admin.domain.ZhxLikeBook;
import com.ruoyi.admin.domain.vo.ZhxBookAndInfoVo;
import com.ruoyi.admin.service.IZhxLikeBookService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户点赞书籍Controller
 * 
 * @author ruoyi
 * @date 2024-11-11
 */
@RestController
@RequestMapping("/public/ZhxLikeBook")
public class PubZhxLikeBookController extends BaseController
{
    @Autowired
    private IZhxLikeBookService zhxLikeBookService;

    /**
     * 查询用户点赞书籍列表（未使用）
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxLikeBook:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZhxLikeBook zhxLikeBook)
    {
        startPage();
        List<ZhxLikeBook> list = zhxLikeBookService.selectZhxLikeBookList(zhxLikeBook);
        return getDataTable(list);
    }

    /**
     * 导出用户点赞书籍列表（未使用）
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxLikeBook:export')")
    @Log(title = "用户点赞书籍", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZhxLikeBook zhxLikeBook)
    {
        List<ZhxLikeBook> list = zhxLikeBookService.selectZhxLikeBookList(zhxLikeBook);
        ExcelUtil<ZhxLikeBook> util = new ExcelUtil<ZhxLikeBook>(ZhxLikeBook.class);
        util.exportExcel(response, list, "用户点赞书籍数据");
    }

    /**
     * 获取用户点赞书籍详细信息（未使用）
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxLikeBook:query')")
    @GetMapping(value = "/{likeBookId}")
    public AjaxResult getInfo(@PathVariable("likeBookId") Long likeBookId)
    {
        return success(zhxLikeBookService.selectZhxLikeBookByLikeBookId(likeBookId));
    }

    /**
     * 新增用户点赞书籍（未使用）
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxLikeBook:add')")
    @Log(title = "用户点赞书籍", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhxLikeBook zhxLikeBook)
    {
        return toAjax(zhxLikeBookService.insertZhxLikeBook(zhxLikeBook));
    }

    /**
     * 修改用户点赞书籍（未使用）
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxLikeBook:edit')")
    @Log(title = "用户点赞书籍", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhxLikeBook zhxLikeBook)
    {
        return toAjax(zhxLikeBookService.updateZhxLikeBook(zhxLikeBook));
    }

    /**
     * 删除用户点赞书籍（未使用）
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxLikeBook:remove')")
    @Log(title = "用户点赞书籍", businessType = BusinessType.DELETE)
	@DeleteMapping("/{likeBookIds}")
    public AjaxResult remove(@PathVariable Long[] likeBookIds)
    {
        return toAjax(zhxLikeBookService.deleteZhxLikeBookByLikeBookIds(likeBookIds));
    }


    /**
     * 查询用户点赞书籍列表
     * and书籍信息
     */
//    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxLikeBook:list')")
    @GetMapping("/listLikeBook")
    public TableDataInfo listLikeBook(ZhxLikeBook zhxLikeBook)
    {
        startPage();
        List<ZhxBookAndInfoVo> list = zhxLikeBookService.selectZhxLikeBookListAndInfo(zhxLikeBook);
        return getDataTable(list);
    }

    /**
     * 新增用户点赞书籍
     * 书籍点赞数+1
     */
//    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxLikeBook:add')")
    @Log(title = "用户点赞书籍", businessType = BusinessType.INSERT)
    @PostMapping("/addLikeBook")
    public AjaxResult addLikeBook(@RequestBody ZhxLikeBook zhxLikeBook)
    {
        return toAjax(zhxLikeBookService.insertZhxLikeBookTodo(zhxLikeBook));
    }

    /**
     * 删除用户点赞书籍
     * 书籍点赞数-1
     */
//    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxLikeBook:remove')")
    @Log(title = "用户点赞书籍", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeLikeBook/{likeBookId}")
    public AjaxResult removeLikeBook(@PathVariable Long likeBookId)
    {
        return toAjax(zhxLikeBookService.deleteZhxLikeBookByLikeBookIdTodo(likeBookId));
    }


}
